package Userjava.Userdao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import java.sql.SQLException;

public class bankServer {
    @Autowired
    private TransactionTemplate template;
    @Autowired
    private bankDaoImpl bankDao;
    @Transactional(isolation = Isolation.REPEATABLE_READ,
            propagation = Propagation.REQUIRED,readOnly = false)
    public void transfer(String from,String to,int money){
        try {
            bankDao.jianMoney(from,money);
            bankDao.jiaMoney(to,money);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

  /*  public void transfer(String from,String to,int money){
        template.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                try {
                    bankDao.jianMoney(from, money);
                    bankDao.jiaMoney(to, money);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        });

    }*/
}
